package com.gzsxy.esjy.service.auth.controller.api;

import com.gzsxy.esjy.service.auth.service.UserService;
import com.gzsxy.esjy.service.base.dto.request.UserRequest;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;
import com.gzsxy.esjy.service.base.dto.response.UserRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 用户管理
 * @date 2022/2/7 15:12
 */
@CrossOrigin  //解决跨域
@RefreshScope    //动态刷新配置文件-外部配置文件
@RestController
@RequestMapping("/api/user")
@Api("用户管理")
public class ApiUserController {

    @Autowired
    private UserService userService;


    /**
     * @description: 注册用户
     * @param
     * @return
     */
    @PostMapping("/register")
    @ApiOperation("注册用户")
    public DefaultResponse registerUser(@RequestBody UserRequest userRequest){
        userService.registerUser(userRequest);
        return DefaultResponse.ok();
    }


    @GetMapping("/{id}")
    @ApiOperation("根据id查询用户")
    public DefaultResponse getUserById(@PathVariable String id){
        UserRsp userRsp = userService.getUserById(id);
        return DefaultResponse.ok(userRsp);
    }

    @PutMapping("/edit")
    @ApiOperation("修改用户")
    public DefaultResponse editUser(@RequestBody UserRequest userRequest){
        UserRsp userRsp =userService.editUser(userRequest);
        return DefaultResponse.ok(userRsp);
    }




}
